#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#define MAXN 20005
using namespace std;

int a[MAXN];
map<int, int> pos[5];
int n;

bool cmp(int a, int b){
    int f = 0;
    for (int i=0;i<5;i++)
        f += (pos[i][a] < pos[i][b]);
    return f > 2;
}

int main()
{
    freopen("photo.txt","r", stdin);
    cin >> n;
    for (int i=0;i<5;i++)
    for (int j=0;j<n;j++)
    {
        int x; cin >> x;
        pos[i][x] = j;
        a[j] = x;
    }
    sort(a, a+n, cmp);
    for (int i=0;i<n;i++) cout << a[i] << endl;
    return 0;
}
